<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div>
       <canvas id="cvs" width="400" height="400"></canvas>
    </div>
    <script>
       var canvas = document.getElementById('cvs');
       var context = canvas.getContext("2d");
       function line(x,y,w,cap) {
           context.beginPath()
           context.lineCap = cap
           context.moveTo(x,y)
           context.lineTo(x+w,y)
           context.closePath()
           context.lineWidth = 8       
           context.stroke()
           context.closePath()
       }

       line(10,100,100,'butt')
       line(10,150,100,'round')
       line(10,200,100,'square')
    </script>
</body>
</html>